package com.example.qwe.controller;

import com.example.qwe.entity.Students;
import com.example.qwe.service.StudentService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class StudentController {
    @Autowired
    StudentService studentService;

    @GetMapping("find/{id}")
    public Students findById(@PathVariable Integer id){
        return studentService.findById(id);
    }

    @GetMapping("delete/{id}")
    public void delete(@PathVariable Integer id){
        studentService.deleteById(id);
    }
    @GetMapping("/find/{left}/{right}")
    public  String findIdBetween(@PathVariable Integer left, @PathVariable Integer right){
        return studentService.findIdBetween(left,right).toString();
    }
  @GetMapping("update/{id}/{name}/{sex}/{classes}")
  public void update(@PathVariable Integer id, @PathVariable String name, @PathVariable String sex, @PathVariable String classes){
      Students students=new Students();
      students.setId(id);
      students.setName(name);
      students.setSex(sex);
      students.setClasses(classes);
      studentService.update(students);
  }
    @GetMapping("insert/{id}/{name}/{sex}/{classes}")
    public void insert(@PathVariable Integer id, @PathVariable String name, @PathVariable String sex, @PathVariable String classes){
        Students students=new Students();
        students.setId(id);
        students.setName(name);
        students.setSex(sex);
        students.setClasses(classes);
        studentService.insertId(students);
    }
}
